package com.example.controller.contractManage;

import com.example.entity.Contract;
import com.example.entity.ContractVO;
import com.example.service.contractManage.ContractRenewService;
import com.example.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ----MaxCV工程师---
 *
 * @author wangbiao
 * @date2024/12/7
 * @desc
 */
@RestController
@RequestMapping("/sys/renew")
public class ContractRenewController {
    @Autowired
    private ContractRenewService contractRenewService;

    /**
     * 查询全部已通过并且过期的合同
     */
    @PostMapping("/renewList")
    public R renewList(@RequestBody ContractVO contractVO){
        PageHelper.startPage(contractVO.getPageNum(),contractVO.getPageSize());
        List<ContractVO> list = contractRenewService.renewList(contractVO);
        PageInfo<ContractVO> info = new PageInfo<>(list);
        return R.ok(info);
    }

    /**
     * 不续签,将renew_state置为0
     */
    @GetMapping("/unRenew")
    public R unRenew(int contractId){
        int i= contractRenewService.unRenew(contractId);
        if (i>0){
            return R.ok();
        }
        return R.fail();
    }


    /**
     * 续签,将原合同的部分信息进行更新
     */
    @PostMapping("/renew")
    public R renew(@RequestBody Contract contract){
        Integer i = contractRenewService.renew(contract);
        if (i>0){
            return R.ok();
        }
        return R.fail();
    }


}
